<?php
namespace Tongcheng\Controller;
use Think\Controller;
class JoinController extends CommonController {
    public function index(){
    	$model = M("Join");
    	$map['wid'] = session('wid');
    	$list = $model->where($map)->select();
        $this->assign('list',$list);
        $this->display();
    }

    public function add(){
        if(IS_AJAX){
            $model = M("Join");
            $new['wid'] = session('wid');
            $new['title'] = I('post.title');
            $new['days'] = I('post.days');
            $new['price'] = I('post.price');
            $new['create_time'] = date("Y-m-d H:i:s");
            if($model->add($new)){
                $this->success('添加成功！');
            }else{
                $this->error('网络忙，请稍后再试！');
            }
        }else{
            $this->display();
        }
    }

    public function edit(){
    	$model = M("Join");
    	$map['wid'] = session('wid');
        $map['id'] = $_GET['id'];
        if(IS_AJAX){
            $new['title'] = I('post.title');
            $new['days'] = I('post.days');
            $new['price'] = I('post.price');
            $model->where($map)->save($new);
            $this->success('修改成功！');
        }else{
            $vo = $model->where($map)->find();
            $this->assign('vo',$vo);
            $this->display('add');
        }
    }

    public function del(){
        $model = M("Join");
        $map['wid'] = session('wid');
        $map['id'] = $_POST['id'];

        if($model->where($map)->delete()){
            $this->success("删除成功！");
        }else{
            $this->error("网络忙，请稍后再试！");
        }
    }
}